//
// Created by DengLibin on 2018/12/13 0013.
//
/**
 * list 双向链表，list不可以随机存取元素，所以不支持at.(pos)函数与[]操作符
 */
#include <iostream>
#include <list>
using namespace std;
void showList(list<int> &l)
{
    cout << "list大小:" << l.size()<<"->";

    for (list<int >::iterator it = l.begin(); it != l.end(); it++)
    {
        cout << *it << ",";
    }
    cout << endl;
}
void myList()
{
    list<int>l;
    for (int i = 0; i < 10; i++)
    {
        l.push_back(i);//在尾部插入
        l.push_front(i);//在头部插入
    }
    showList(l);//9,8,7,6,5,4,3,2,1,0,0,1,2,3,4,5,6,7,8,9,
    l.pop_back();//删除头部元素
    l.pop_front();//删除尾部元素
    showList(l);//8,7,6,5,4,3,2,1,0,0,1,2,3,4,5,6,7,8,
    l.erase(l.begin(), ++(++(l.begin())));//区间删除(包含头不包含尾,如果头尾相同，也不会删除)
    showList(l);//6,5,4,3,2,1,0,0,1,2,3,4,5,6,7,8,
    l.erase(++l.begin());//删除指定位置的元素
    showList(l);//6,4,3,2,1,0,0,1,2,3,4,5,6,7,8,
    //赋值
    l.front() = 23;
    l.back() = 80;
    showList(l);//23,4,3,2,1,0,0,1,2,3,4,5,6,7,80,
}
int main26()
{
    myList();
    return 0;
}
